/* eslint-disable import/prefer-default-export */
import request from '@/utils/request';
import { pathNameMap } from '@/utils/dictionary';

/**
 * 招聘需求--企业列表
 * 招聘需求--用人部门列表
 * 招聘需求--我的招聘任务列表
 */
export async function getPositionList(params, dictionary) {
    const { pathName } = dictionary;
    const { requestUrl = '' } = pathNameMap.find(v => v.pathName === pathName);
    return request(requestUrl, {
        method: 'POST',
        data: params
    });
}
/**
 * 查询招聘需求相关候选人信息
 * @param {*} params
 */
export async function getCandidateInfo(params) {
    return request('/api/oa/v1/candidate/querycandidatesbyrecruit', {
        method: 'POST',
        data: params
    });
}

/**
 * 获取发起招聘申请的参数
 * @param {string} companyId
 */
export async function getApply(params) {
    return request(`/api/oa/v1/recruit/apply/${params.companyId}`, {
        method: 'GET'
    });
}
/**
 * 招聘详情 职位信息
 */
export async function getRecruitInfo(params, dictionary) {
    const { pathName, fetchType } = dictionary;
    let { requestUrl = '' } = pathNameMap.find(
        v => v.pathName === pathName && v.fetchType === fetchType
    );
    requestUrl = `${requestUrl}/${params.recruitCode}`;
    return request(requestUrl, {
        method: 'GET'
    });
}
/**
 * 招聘详情 招聘进度
 * @param {*} params
 * @param {*} dictionary
 */
export async function getRecruitSchedule(params, dictionary) {
    const { pathName, fetchType, isModal = false } = dictionary;
    let url;
    // isModalFetch 是否是 列表页直接操作 招聘进度
    if (isModal) {
        const { ModalFetch } = pathNameMap.find(v => v.pathName === pathName);
        url = `${ModalFetch}/${params.recruitCode}`;
    } else {
        const { requestUrl } = pathNameMap.find(
            v => v.pathName === pathName && v.fetchType === fetchType
        );
        url = `${requestUrl}/${params.recruitCode}`;
    }

    return request(url, {
        method: 'GET'
    });
}
/**
 * 招聘详情 候选人要求
 * @param {*} params
 * @param {*} dictionary
 */
export async function getCandidateClaim(params, dictionary) {
    const { pathName, fetchType } = dictionary;
    let { requestUrl = '' } = pathNameMap.find(
        v => v.pathName === pathName && v.fetchType === fetchType
    );
    requestUrl = `${requestUrl}/${params.recruitCode}`;
    return request(requestUrl, {
        method: 'GET'
    });
}
/**
 * 招聘任务编辑
 */
export async function postPpdateRecruit(params, dictionary) {
    const { pathName, fetchType, isModal = false } = dictionary;
    let url;
    // isModal 是否是 列表页直接操作 招聘进度
    if (isModal) {
        const { ModalUpdate } = pathNameMap.find(v => v.pathName === pathName);
        url = `${ModalUpdate}`;
    } else {
        const { requestUrl } = pathNameMap.find(
            v => v.pathName === pathName && v.fetchType === fetchType
        );
        url = `${requestUrl}`;
    }

    return request(url, {
        method: 'POST',
        data: params
    });
}
